package keeto.com.vn.bms.ui.widget;

import keeto.com.vn.bms.config.BMSCore;
import keeto.com.vn.bms.ui.activity.R;
import keeto.com.vn.bms.utils.BMSListener;
import keeto.com.vn.bms.utils.BMSSharedPreferences;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class DialogDeleteMsg extends Dialog implements android.view.View.OnClickListener  {

	private Context ctx;
	private Button btnOk;
	private Button btnCancel;
	private BMSSharedPreferences preferences;
	private BMSListener mListener;
	private LinearLayout llParent;
	private TextView tvTitle;
	private TextView tvContent;
	private String msgId;
	private StringBuilder builder;

	public DialogDeleteMsg(Context context, BMSListener mListener, String msgID) {
		super(context);
		this.ctx = context;
		this.mListener = mListener;
		this.preferences = new BMSSharedPreferences(context);
		this.msgId = msgID;
	}


	protected DialogDeleteMsg(Context context, boolean cancelable,
			OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
		// TODO Auto-generated constructor stub
	}

	public DialogDeleteMsg(Context context, int theme) {
		super(context, theme);
		// TODO Auto-generated constructor stub

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.logout_dialog_layout);
		llParent = (LinearLayout)findViewById(R.id.parent_logout_dialog);
		tvTitle  = (TextView)findViewById(R.id.tvTitleDialog);
		tvContent = (TextView)findViewById(R.id.tvContentDialog);

		btnOk = (Button)findViewById(R.id.btn_ok_logout);
		btnCancel = (Button)findViewById(R.id.btn_cancel_logout);

		tvTitle.setText(ctx.getResources().getString(R.string.title_delete_msg));
		tvContent.setText(ctx.getResources().getString(R.string.content_delete_msg));
		btnOk.setOnClickListener(this);
		btnCancel.setOnClickListener(this);
		this.setCanceledOnTouchOutside(true);
		Rect displayRectangle = new Rect();
		Window window = this.getWindow();
		window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle);
		llParent.setMinimumWidth((int) (displayRectangle.width()* 0.9f));
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btn_ok_logout:
			builder = new StringBuilder();
			builder.append("[\"");
			builder.append(msgId);
			builder.append("\"]");
			BMSCore.getInstance(ctx).taskSendDeleteMessager(builder.toString(), preferences.getUserAuthKey(ctx), mListener);
			this.dismiss();
			msgId = "";
			break;
		case R.id.btn_cancel_logout:
			this.dismiss();
			break;

		default:
			break;
		}
	}

}
